package com.coco.controller;

import com.coco.model.VideoCondition;
import com.coco.model.VideoModel;
import com.coco.model.VideoNum;
import com.coco.service.VideoService;
import com.coco.utils.CoPageResp;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author GHOSTLaycoo
 * @date 2020/4/13 0013 - 上午 8:42
 */
@RestController
@RequestMapping("/video")
@Slf4j
public class VideoController {
    @Autowired
    private VideoService videoService;

    @ApiOperation(value = "查询视频数据")
    @PostMapping("/getVideosByCondition")
    public ResponseEntity<CoPageResp<VideoModel>> getVideosByCondition(@RequestBody VideoCondition videoCondition){
        return ResponseEntity.ok(videoService.getVideosByCondition(videoCondition));
    }

    @ApiOperation(value = "删除视频")
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Integer> delete(@PathVariable String id){
        return ResponseEntity.ok(videoService.delete(id));
    }

    @ApiOperation(value = "新增视频")
    @PostMapping("/save")
    public ResponseEntity<Integer> save(@RequestBody VideoModel videoModel){
        int result = videoService.save(videoModel);
        return ResponseEntity.status(HttpStatus.CREATED).body(result);
    }

    @ApiOperation(value = "修改视频信息")
    @PostMapping("/update")
    public ResponseEntity<Integer> update(@RequestBody VideoModel videoModel){
        int result = videoService.update(videoModel);
        return ResponseEntity.status(HttpStatus.CREATED).body(result);
    }

    @ApiOperation(value = "修改视频浏览次数")
    @PutMapping("/updateWatch/{id}")
    public ResponseEntity<Integer> updateWatch(@PathVariable("id") String id){
        int result = videoService.updateWatch(id);
        return ResponseEntity.ok(result);
    }

    @ApiOperation(value = "修改视频点赞次数")
    @PutMapping("/updateWatch/{id}/{sum}")
    public ResponseEntity<Integer> updateStar(@PathVariable("id") String id,@PathVariable("sum") int sum){
        int result = videoService.updateStar(id,sum);
        return ResponseEntity.ok(result);
    }

    @ApiOperation(value = "视频类别占比数据")
    @GetMapping("/type/nums")
    public ResponseEntity<List<VideoNum>> getTypeNums(){
        List<VideoNum> typeNums = videoService.getTypeNums();
        return ResponseEntity.ok(typeNums);
    }

    @ApiOperation(value = "通过id获取视频数据")
    @GetMapping("/getVideoById/{id}")
    public ResponseEntity<VideoModel> getVideoById(@PathVariable("id") String id){
        return ResponseEntity.ok(videoService.getVideoById(id));
    }
}
